package com.lagou.firstStageFourthModel.First;

import java.io.Serializable;

/**
 * 学生类
 */
public class Student implements Serializable {

    // 序列化的版本号 与序列化操作有关
    static final long serialVersionUID = 7818375828146090155L;

    private int number;
    private String name;
    private int age;

    public Student() {
    }

    public Student(int number, String name, int age) throws StudentAgeException, StudentNumberException {
        setNumber(number);
        setName(name);
        setAge(age);
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) throws StudentNumberException {
        // 判断数值是否合理
        if (number <= 0) {
            // 不合理 抛出自定义异常
            throw new StudentNumberException("学号数值不合理");
        } else {
            this.number = number;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws StudentAgeException {
        // 判断数值是否合理
        if (age <= 0 || age > 150) {
            // 不合理 抛出自定义异常
            throw new StudentAgeException("年龄数值不合理");
        } else {
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return "Student{学号：" + number + ", 姓名：'" + name + ", 年龄:" + age + '}';
    }
}
